//
//  ZYVisitorTableViewController.swift
//  weiboZY
//
//  Created by 赵勇 on 16/5/11.
//  Copyright © 2016年 赵勇. All rights reserved.
//

import UIKit

class ZYVisitorTableViewController: UITableViewController {

    // 用户是否登录的标记
    var userLogin = ZYUserAccountViewModel.sharedUserAccount.isLogin
    // 访客视图
    var visitorView: ZYVisitorView?
    
    
    override func loadView() {
        if userLogin {
            super.loadView()
        } else {
            // 没有登录的情况下，创建访客视图
            visitorView = ZYVisitorView()
          
            visitorView!.callBackClosure = { [weak self] in
                self?.requestOAuthLogin()
//                print("闭包回调")
//                print(self)
            }
            
            view = visitorView
            setUpNavUI()
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()


    }

    // 设置导航栏按钮
    private func setUpNavUI() {
        // 添加注册与登录按钮
     navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", fontSize: 15, target: self, action: "registerAction")
     navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", fontSize: 15, target: self, action: "loginAction")
        
    }
    
    // MARK: -注册与登录按钮点击事件
   @objc private func registerAction() {
        
//        print("registerAction")
       requestOAuthLogin()
    }
    
    @objc private func loginAction() {
//        print("loginAction")
        requestOAuthLogin()
    }
   
     private func requestOAuthLogin() {
        
        let oauthVc = ZYOAuthViewController()
        let nav = UINavigationController(rootViewController: oauthVc)
        presentViewController(nav, animated: true, completion: nil)
        
    }

}











